
function showDictList2() {
	showLoading("查询中...");
	$.ajax({url:"dict/listPage2.do", type:"get",async:true, dataType:"html", success:function (data) {
		$("#mainForm").html(data);
		dicttable=$("#dictTable").table({
			width:"100%", 
			defaultOrderBy:"dictPaixu",
			defaultOrderType:"asc",
			form:{
				url:"comm/search.do", 
				id:"#dictSearchForm", 
				type:"post", 
				pageNumberText:"#pageNum"
			}, 
			pageable:false,
			selectable:true, 
			colums:[
			    {columnName:"类别名称",width:'45%', name:"title", sortable:false,handle:"editDict2"},
				{columnName:"类型名称",width:'55%', name:"value", sortable:false,handle:"editDict2"},
				],
			orderBy:{
				field:"num",
				type:"asc"
			}
		});
		hideLoading();
		//新建按钮
		$("#createBtn").click(function(){
			editDict2();
		});
		//查询按钮
		$("#searchBtn").click(function(){
			var comvalue= $("#categoryList").val();
			if(comvalue == null || comvalue == ''){
				showDialog("请选择 [ 字典类别名 ] ");
				return;
			}
			$("#pageNum").val(1);
			dicttable.refresh();
		});
		//删除按钮
		$("#deleteBtn").click(function(){
				var ids = getCheckboxSelectItems();
				if (ids == "") {
					return;
				}
				$("#msgDialog").html("<p>确定要删除这些记录吗？</p>");
				$("#msgDialog").dialog({
					modal:true,
					width:250,
					height:160,
					buttons:{"确定":function(){
								$(this).dialog("close");
								$.ajax({url:"dict/delete.do?t="+(new Date())+"&" + ids, type:"get", dataType:"json", success:function (data) {
								if (data.success) {
									showDialog("删除成功");
									dicttable.refresh();
								}else{
									showDialog("删除失败，原因："+data.message);
								}
						}});
							},"取消":function(){
								$(this).dialog("close");
							}
					},close:function(){$(this).dialog('destroy');}
				});	
		});
		$(".comboBox").kendoComboBox({filter:"contains", suggest:true });
		// 拖拽处理
		$( "#dictTable tbody" ).sortable({ 
			 axis: 'y' ,
			 tolerance: 'pointer',
			 cursor: 'crosshair',
			 helper: fixHelper,
			 revert: true,
			 cursor: 'move', //拖动的时候鼠标样式 
			 containment: 'parent',
			 delay:100,
			 start:function(e, ui){ 
                    ui.helper.addClass("moveAble");
                    return ui; 
             }, 
             stop:function(e, ui){ 
             	var i=0;
             	$(".records tr").each(function(){
             		$(this).removeClass("r1").removeClass("r2");
             		if(i%2==0){
             			$(this).addClass("r1");
             		}else{
             			$(this).addClass("r2");
             		}
             		i++;
             	});
                 ui.item.removeClass("ui-state-highlight"); //释放鼠标时，要用ui.item才是释放的行  
                 ui.item.removeClass("moveAble");
                 return ui; 
             }  
		}).disableSelection();
		//排序保存按钮
		$("#sortSaveBtn").click(function(){
			saveSortDict();
		});
	}});
}  
//编辑操作，
//如果传了id值，就是编辑，如果没有id值，就是新建
function editDict2(id) {
	var title = "添加字典";
	var leibie = $("#categoryList").val();
	var dict = "?t="+(new Date());
	if (id) {
		title = "编辑字典";
	}
	$.ajax( {
		url : "dict/edit2.do" + dict,
		type : "post",
		data : {
			"dict.id" : id,
			"type" : leibie
		},
		dataType : "html",
		success : function(data) {
			$("#commonDialog").html(data);
			$("#commonDialog").dialog( {
				title : title,
				modal : true,
				width : 659,
				height : 206,
				resizable : false,
				buttons : {
					'保存' : function() {
						saveDict2();
					},
					'取消' : function() {
						$("#commonDialog").dialog('close');
					}
				}
			});
			$("#saveBtn").click(saveDict);
			//使用jquery默认消息做验证
		validator = $("#editForm").validate( {
			rules : {
				"dict.title" : {
					required : true,
					minlength : 2,
					maxlength : 100
				},
				"dict.value" : {
					required : true,
					maxlength : 100
				},
				"dict.code" : {
					required : true,
					maxlength : 100
				}
			},
			messages : {
				"dict.title" : {
					required : "必填",
					minlength : "最少两个字",
					maxlength : "最长50字"
				},
				"dict.value" : {
					required : "必填",
					maxlength : "最长50字"
				},
				"dict.code" : {
					required : "必填",
					maxlength : "最长50字"
				}
			}
		});
	}
	});
}  
//保存
function saveDict2() {
	if (!validator.form()) {
		return;
	}
	$("#editForm").ajaxSubmit( {
		url : "dict/save2.do",
		type : "post",
		dataType : "json",
		success : function(data) {
			$("#commonDialog").dialog("close");
			if (data.success) {
				showDialog("保存成功");
				dicttable.refresh();
			} else {
				showDialog("保存失败,原因->" + data.message);
			}
		}
	});
}